﻿using log4net;
using System;
using System.Text;

namespace JNPF.Utils
{
    /// <summary>
    /// Log
    /// 版 本：V3.0.0
    /// 版 权：引迈信息技术有限公司（https://www.jnpfsoft.com）
    /// 作 者：JNPF开发平台组
    /// </summary>
    public class Log
    {
        /// <summary>
        /// 日志实体类
        /// </summary>
        private ILog logger;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="log">日志操作对象</param>
        public Log(ILog log)
        {
            this.logger = log;
        }
        /// <summary>
        /// 调试日志
        /// </summary>
        /// <param name="message">消息</param>
        public void Debug(object message)
        {
            this.logger.Debug(this.LogTemplate(message));
        }
        /// <summary>
        /// 错误日志
        /// </summary>
        /// <param name="message">消息</param>
        public void Error(object message)
        {
            this.logger.Error(this.LogTemplate(message));
        }
        /// <summary>
        /// 信息日志
        /// </summary>
        /// <param name="message">消息</param>
        public void Info(object message)
        {
            this.logger.Info(this.LogTemplate(message));
        }
        /// <summary>
        /// 警告日志
        /// </summary>
        /// <param name="message">消息</param>
        public void Warn(object message)
        {
            this.logger.Warn(this.LogTemplate(message));
        }
        /// <summary>
        /// 日志模板
        /// </summary>
        /// <param name="message">信息</param>
        /// <returns></returns>
        private string LogTemplate(object message)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("1. 时间: " + DateTime.Now + "    \r\n");
            sb.Append("2. 内容: " + message + "\r\n");
            sb.Append("-----------------------------------------------------------------------------------------------------------------------------\r\n");
            return sb.ToString();
        }
    }
}
